from core.support import set_cutscene
from core.item import Item
from core.action import Action
from core.support import get_game
from rooms.tribe import Tribe

class Gold(Item):
    def __init__(self):
        Item.__init__(self, "gold")    # do basic initialization for every item
        
        # build list of actions
        self.add_action(GiveGold)
    
    def get_description(self):
        return "gold coins"

# define actions for this item

class GiveGold(Action):
    def __init__(self):
        Action.__init__(self, "give_gold")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Use gold coins"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
    
    # only works in basement. add cutscene
    def do_action(self,game,room,request):
        if room.get_id() == 'tribe':
            if room.gold_given:
                set_cutscene("You give the tribe more gold.")
            else:
                player = game.get_player()
                player.pop_item('gold')
                room.gold_given = True
                set_cutscene("You give your gold coins to the tribe.  In exchange, they indicate they will help you with whatever you need!")
        else:
            set_cutscene("Nothing to use the gold coins with here.")
        return
    
    def is_enabled(self):
        game = get_game()
        room = game.get_room('tribe', Tribe)
        
        if room.gold_given:
            return False
        else:
            return True